package com.M10.BE.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.M10.BE.R;
import com.fn.useries.model.Inve;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Lenovo
 * @desc
 * @time 2018/3/8 15:19
 */

public class InveAdapter extends RecyclerView.Adapter<InveAdapter.MasonryView> {
    private List<Inve> assets;
    private Context ctx;

    public InveAdapter(ArrayList<Inve> list, Context context) {
        assets = list;
        ctx = context;
    }

    @Override
    public InveAdapter.MasonryView onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_inve, parent, false);
        return new InveAdapter.MasonryView(view);
    }

    @Override
    public void onBindViewHolder(InveAdapter.MasonryView holder, final int position) {
        holder.name.setText(assets.get(position).getName());
        holder.code.setText(assets.get(position).getCode());
        holder.cnum.setText(assets.get(position).getCnum());
        holder.num.setText(assets.get(position).getCheckNum());
        if (assets.get(position).getCheckNum().equals("1")) {
            holder.num.setTextColor(Color.parseColor("#FAF43009"));
        }
//        holder.itemView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Intent intent = new Intent(ctx, AssetInfoActivity.class);
//                intent.putExtra("asset", assets.get(position));
//                ctx.startActivity(intent);
//            }
//        });
    }

    @Override
    public int getItemCount() {
        return assets.size();
    }

    public static class MasonryView extends RecyclerView.ViewHolder {
        TextView name;
        TextView code;
        TextView cnum;
        TextView num;

        public MasonryView(View itemView) {
            super(itemView);
            name = (TextView) itemView.findViewById(R.id.name);
            code = (TextView) itemView.findViewById(R.id.code);
            cnum = (TextView) itemView.findViewById(R.id.cnum);
            num = (TextView) itemView.findViewById(R.id.num);
        }

    }
}

